package com.aistar.service.user.impl;

import com.aistar.mapper.*;
import com.aistar.model.dto.user.ResumeViewAndCompanyDTO;
import com.aistar.model.entity.Resume;
import com.aistar.model.entity.ResumeView;
import com.aistar.service.user.IResumeViewService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class ResumeViewServiceImpl implements IResumeViewService {
    @Autowired
    private ResumeViewMapper resumeViewMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private ResumeMapper resumeMapper;

    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public List<ResumeView> loadAll() {
        return resumeViewMapper.loadAll();
    }
    @Override
    public List<ResumeViewAndCompanyDTO> viewMe(Integer employeeId) {
        List<ResumeViewAndCompanyDTO> lists = new ArrayList<>();
        for (Resume resume :resumeMapper.findByEmployeeId(employeeId)){
            for (ResumeView resumeView : resumeViewMapper.findById(resume.getId())){
                ResumeViewAndCompanyDTO resumeViewAndCompanyDTO = new ResumeViewAndCompanyDTO();
                resumeViewAndCompanyDTO.setResumeView(resumeView);
                resumeViewAndCompanyDTO.setCompany(companyMapper.findById(resumeView.getCompanyId()));
                lists.add(resumeViewAndCompanyDTO);
            }
        }
        return lists;
    }
}
